package com.arvato.common.advice;

import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;  
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.arvato.minipro.bean.bean_dto.common.Result;  
/**
 * 统一捕捉程序运行异常返回给前台错误信息
 * @author ZHAN655
 */
@ControllerAdvice  
public class GlobalExceptionHandler {  
	
	Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
	
	public int count = 0;
	
	@ResponseBody
    @ExceptionHandler(value = Exception.class)  
    public Result defaultErrorHandler(HttpServletRequest req, Exception e)  {  
    	// 打印异常信息：  
    	logger.error("<<<<<<<<<第" + count++ + "次发生异常>>>>>>>>" );
    	logger.error("异常明细：", e);
        return Result.fail("服务器内部错误，报错信息：" + e, e);
  }  
}  